//css样式集合
import "src/styles/css/reset.css";
import "src/styles/scss/font-awesome/font-awesome.scss";
import "src/styles/scss/public.scss";

//导入路由
import routes from "./routers/router";
import { cookie } from "src/utils/tools";
import store from "./store";

import "./directive/directive";
//导入过滤器
import "src/filter/filter";

import "src/utils/useElement"; //引入element ui组件

// import "src/styles/theme/index.css";
import * as monaco from "monaco-editor"
//组件
import Vue from "vue";
import VueRouter from "vue-router";

// import TouchRipple from 'vue-touch-ripple'

//方法
import { mapActions } from "vuex";

//vue初始化注册组件
// Vue.use(TouchRipple);
Vue.use(VueRouter);

//routes初始化
const router = new VueRouter({ routes });


import Box from "src/components/common/Box"
import SearchContainer from "src/components/common/SearchContainer"
Vue.component('Box',Box);
Vue.component('SearchContainer',SearchContainer)
// 内外部用户标志位
// if(__CONFIGMODE__ == 'test'){
//     location.pathname == API.innerHost ? storage.set('isInnerLogin',true) : storage.set('isInnerLogin',false);
// }else{
//     location.host == API.innerHost ? storage.set('isInnerLogin',true) : storage.set('isInnerLogin',false);
// }

// storage.set("isInnerLogin", true);

// vue-router的跳转是基于hash的
if (!GetQueryString("ticket")) {
  // console.log(location.origin + location.pathname, encodeURIComponent(location.origin + location.pathname + "#/platform"));
  window.location.href = "http://nsso.zhonganonline.com/login?service=za-pre-stormeye-console&target=" + encodeURIComponent(location.origin + location.pathname + "#/platform");
} else {
  router.beforeEach((to, from, next) => {
    if (!cookie.get("isVisitedPlatform")) {
      to.path !== "/platform" ? next({ path: "/platform" }) : next();
    } else if (!cookie.get("isVisitedProduct")) {
      to.path !== "/product" ? next({ path: "/product" }) : next();
    } else {
      next();
    }
    // let isLogin = storage.get("isLogin");
    // // 外部登录
    // if (storage.get("isInnerLogin")) {
    //   if (!isLogin && to.path !== "/login") {
    //     // 未登录且不为登录界面时
    //     next({ path: "/login" }); // 跳到 登录页
    //   } else {
    //     next(); // 正常跳转
    //   }
    // } // 内部登录
    // else {
    //   if (!isLogin && to.path !== "/") {
    //     // 未登录且不为主页时
    //     next({ path: "/" }); // 跳到 主页 这种跳转会造成死循环
    //   } else {

    //   }
    // }
  });
}

function GetQueryString(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return unescape(r[2]);
  return null;
}

//sessionStorage历史路由初始化
// function initSessionStorage() {

//     if (!storage.get('HISTORY_ROUTES')) {
//         storage.set('HISTORY_ROUTES', {
//             '/': {
//                 name: "首页",
//                 url: '',
//                 iconCls: 'fa fa-plus',
//             }
//         })
//     }
// }
// initSessionStorage();

//vue初始化
var app = new Vue({
  router,
  store,
  computed: {
    loading: function() {
      return this.$store.state.Main.loading; //遮罩
    }
  },
  methods: {
    ...mapActions(["addHistoryRoute"])
  },
  watch: {
    $route: function(route) {
      let self = this;
      let params = { route, router, self };
      this.addHistoryRoute(params); //路由改变执行
    }
  }
}).$mount("#app");
